package com.chanceit.ssss.adapters;

import org.gl.utils.lg;

import android.app.Activity;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentStatePagerAdapter;

import com.chanceit.ssss.activity.R;
import com.chanceit.ssss.data.DataSources;
import com.chanceit.ssss.fragments.BaseFragment;
import com.chanceit.ssss.fragments.BusinessListFragment;
import com.chanceit.ssss.fragments.CarerDisPowerListFragment;
import com.chanceit.ssss.fragments.CarerListFragment.OnListFragmentSelectedListener;
import com.chanceit.ssss.fragments.CarerLostListFragment;

public class CareCarTabPagerAdapter extends FragmentStatePagerAdapter implements
		OnListFragmentSelectedListener {
	Activity context;
	String tabs[] = new String[3];
	Fragment[] fagments = new Fragment[tabs.length];
	final static public int[] icons = new int[] { R.drawable.ic_srtx,
			R.drawable.ic_miss, R.drawable.ic_menu_dispower, };


	public CareCarTabPagerAdapter(FragmentManager fm, Activity context) {
		super(fm);
		this.context = context;
		tabs = new String[] {
		context.getString(R.string.tab_title_expire_birthday),
				context.getString(R.string.tab_title_kehuliushi), "断电提醒" };
		// tabs = new String[] {
		// context.getString(R.string.tab_title_yichangcanshu),
		// context.getString(R.string.tab_title_kehuliushi),
		// context.getString(R.string.tab_title_cheliangguzhang),
		// context.getString(R.string.tab_title_maintain_first),
		// context.getString(R.string.tab_title_expire_fix),
		// context.getString(R.string.tab_title_expire_maintain),
		// context.getString(R.string.tab_title_expire_insurance),
		// context.getString(R.string.tab_title_expire_check_year),
		// context.getString(R.string.tab_title_expire_car),
		// context.getString(R.string.tab_title_expire_birthday), };
	}

	// 当前车速,发送机转速,电瓶电压,冷却液温度,发动机负载,节气门位置,大气压,进气歧管绝对压力,空气流量,环境空气温度,进气温度,OBD协议,OBD标准,燃油量
	@Override
	public Fragment getItem(int position) {
		Fragment fragment = fagments[position];
		if (fragment == null) {
			switch (position) {
			
			case 0:
				fragment = new BusinessListFragment(
						DataSources.BusinessType_birthday, position);// 生日
				fagments[position] = fragment;
				break;

			case 1:
				fragment = new CarerLostListFragment(
						DataSources.BusinessType_kehuliushi, position);// 客户流失
				fagments[position] = fragment;
				break;
			case 2:
				fragment = new CarerDisPowerListFragment(
						DataSources.BusinessType_kehuduandian, position);// 断电提醒
				fagments[position] = fragment;
				break;
			}
		}
		return fragment;
	}

	@Override
	public int getCount() {
		return tabs.length;
	}

	@Override
	public CharSequence getPageTitle(int position) {
		return tabs[position];
	}

	String TAG = "SectionPagerAdpater";

	public void sendMessage(int postion) {
		if (fagments[postion] != null
				&& fagments[postion] instanceof BaseFragment) {
			((BaseFragment) fagments[postion]).receiveMessage(null);
		} else {
			lg.e(TAG,
					"Exception,the fragment is null,or not BaseFragment ,so it can not receive message,");
		}
	}

	@Override
	public void onArticleSelected(int position) {

	}
}